package com.Akronmcp.hb;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

/**监听器类*/
public class HbListener implements Listener{
	
	@EventHandler(priority = EventPriority.LOW)
	public void onCom(PlayerCommandPreprocessEvent e) 
	{
		String m = e.getMessage().trim();
		String book = HbLoader.cmds.get(m);
		if(book!=null)
		{
			e.setCancelled(true);
			e.getPlayer().performCommand("hb open "+book);
		}
	}
	
	@EventHandler(priority = EventPriority.LOW)
	public void onCom(PlayerInteractEvent e) 
	{
		if(!HbLoader.items.isEmpty())
		{
			Player p = e.getPlayer();
			ItemStack item = p.getInventory().getItemInMainHand();
			if(item!=null)
			{
				int itemi = item.getTypeId();
				String book = HbLoader.items.get(itemi);
				if(book!=null)
				{
					e.setCancelled(true);
					e.getPlayer().performCommand("hb open "+book);
				}
			}
		}
	}
}
